package com.anysoft.controller;

import com.anysoft.model.GoodsInfo;
import com.anysoft.model.GoodsModel;
import com.anysoft.model.TestUserInfo;
import com.anysoft.model.UsersInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/prac")
public class PracController {
    @RequestMapping("/test")
    public String test(Model model) {
        TestUserInfo info = new TestUserInfo();
        model.addAttribute("uname", info.getUname());
        model.addAttribute("country", info.getCountry());
        model.addAttribute("user", info);
        return "test";
    }

    @RequestMapping("/testForm")
    public String testForm(TestUserInfo user, Model model) {
        String uname = user.getUname();
        String country = user.getCountry();
        int age = user.getAge();
        double score = user.getScore();
        model.addAttribute("name", uname);
        model.addAttribute("country", country);
        return "test";
    }

    @RequestMapping("/testPathVariable/{uname}/{country}")
    public String testPathVariable(@PathVariable String country, @PathVariable String uname, Model model) {
        model.addAttribute("name", uname);
        model.addAttribute("country", country);
        return "test";
    }

    @RequestMapping("/input")
    public String goodsInput(){
        return "input";
    }

    @RequestMapping("/converter")
    public String myConverter(@RequestParam("goods") GoodsInfo g, Model model){
        model.addAttribute("goods", g);
        return "showGoods";
    }

    @RequestMapping("/inputFormat")
    public String goodsInputFormatter() {
        return "inputFormatter";
    }

    @RequestMapping("/formatter")
    public String myFormatter(GoodsModel gm,Model model){
        model.addAttribute("goods",gm);
        return "showGoodsFormatter";
    }
}
